#ifndef WSYPERSPECTIVECAMERA_H
#define WSYPERSPECTIVECAMERA_H

#include "geometry/math3d.h"
#include "geometry/vertex3D.h"
#include "wsymath/matrix3d.h"

#include <QOpenGLWidget>

/** 王诗阳透视摄像机对象 */
class WSYPerspectiveCamera: public QObject {
public:
    WSYPerspectiveCamera() {
        this->fov = 45;
        this->aspect = 1;
        this->near1 = 2;
        this->far1 = 4000;
        this->cameraMatrix = Matrix3D::newInstance();
        this->cameraLookAtDirectionNew = new GLfloat[3];
        this->nCameraLookAtDirectionNew = new GLfloat[3];
        this->xDirectionNew = new GLfloat[3];
        this->yDirectionNew = new GLfloat[3];
        this->cameraUpNew = new GLfloat[3];
        this->positiveMatrixNew = Matrix3D::newInstance();
        this->negativeMatrixNew = Matrix3D::newInstance();
        this->negativeMiddleMatrixNew = Matrix3D::newInstance();
        this->middleMatrixNew = Matrix3D::newInstance();
        this->perspectiveMatrixNew = Matrix3D::newInstance();
        setUpright(0, 0, 1);
    }
    //~WSYPerspectiveCamera();
    virtual GLfloat *getCameraMatrix();
    virtual QMatrix4x4 *getCameraMatrix2();
    virtual Vertex3D *getPosition() {
        return position;
    }
    virtual Vertex3D *getLookAt() {
        return lookAt;
    }
    virtual Vector3D *getUpright() {
        return cameraUp;
    }
    virtual void setUpright(double dX, double dY, double dZ) {
        cameraUp->setValues(dX, dY, dZ);
        cameraUpNew[0] = dX; cameraUpNew[1] = dY; cameraUpNew[2] = dZ;
    }
    virtual void setAspect(double asp) {
        aspect = asp;
    }
    virtual void setPosition(double x, double y, double z) {
        position->setValues(x, y, z);
    }
    virtual void setLookAt(double x, double y, double z) {
        lookAt->setValues(x, y, z);
    }
    virtual double getFOV() {
        return fov;
    }
    virtual void setFar(double farValue) {
        far1 = farValue;
    }
private:
    double fov; double aspect; double near1; double far1;
    Vertex3D *position = new Vertex3D(60, -120, 60);
    Vertex3D *lookAt = new Vertex3D(0, 0, 0);
    Vector3D *cameraUp = new Vector3D(0, 0, 1);
    GLfloat *cameraMatrix;
    GLfloat *cameraLookAtDirectionNew;
    GLfloat *nCameraLookAtDirectionNew;
    GLfloat *xDirectionNew, *yDirectionNew;
    GLfloat *cameraUpNew;

    GLfloat *positiveMatrixNew, *negativeMatrixNew;

    GLfloat *negativeMiddleMatrixNew;

    GLfloat *middleMatrixNew, *perspectiveMatrixNew;
};

#endif // WSYPERSPECTIVECAMERA_H
